<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action = $_REQUEST['act'];
	$start		=	$_REQUEST['start'];
    $end		=	$_REQUEST['end'];
	
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("SELECT  	persons.id,
    	    									persons.`name`,
												COUNT(*) AS `work`,
												0 AS   `test`
									FROM 		`warehouse_producing`
									JOIN 		persons ON persons.id = warehouse_producing.person_id
									WHERE       `warehouse_producing`.date >= '$start' AND `warehouse_producing`.date <= '$end'
									GROUP BY 	persons.id
									
									UNION ALL
									
									SELECT  	persons.id,
									    	    persons.`name`,
												0 AS   `work`,
												COUNT(*) AS `test`
									FROM 		`warehouse_producing`
									JOIN        users ON users.id = warehouse_producing.tester_id
									JOIN 		persons ON persons.id = users.person_id
									WHERE       `warehouse_producing`.date >= '$start' AND `warehouse_producing`.date <= '$end'
									GROUP BY 	`warehouse_producing`.`tester_id`");
												
			$output = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$output['aaData'][] = $row;
			}
			
			echo json_encode( $output );

	        break;	    
	    default:
	       	echo "null";
	}
?>